<template>
	<view class="container">
		<view class="title">{{detail.title}}</view>
		<view class="row flex-row">
			<text class="text" style="color: #777;!important">{{detail.createTime}}</text>

			<view class="views" style="display: flex;padding-right: 22rpx;color: #777;!important">
				<image src="../../static/img/eye.png" style="width: 40rpx;height: 40rpx;padding-right: 10rpx;">
				</image>{{detail.viewCount}}
			</view>
		</view>
		<view class="content">
			<u-parse :content="detail.content" :selectable="true"></u-parse>
		</view>
		<view style="padding-top: 30rpx;padding-left: 30rpx;padding-right: 30rpx;">
			<u-divider></u-divider>
		</view>
		<view class="footer">
			<text>Zlwblog</text>
			<text>http://121.37.246.63</text>
		</view>
		<comment-box :articleId="articleId"></comment-box>
		<bottom-comment @callParentFunc="getDetail"
			:item='{"likeTotal": detail.likeCount,"commentTotal": commentTotal,"liked":detail.liked,"aid":detail.id}'></bottom-comment>
		<u-loading-page :loading=" loading" loading-text="loading..."></u-loading-page>
		<u-back-top :scroll-top="scrollTop" top="600"></u-back-top>
	</view>
</template>

<script>
	import {
		getArticle
	} from '../../api/article'
	import MarkdownIt from 'markdown-it'
	import {
		getArticleComment
	} from '../../api/comment';

	const md = new MarkdownIt();
	export default {
		data() {
			return {
				scrollTop: 0,
				detail: null,
				loading: false,
				list: [],
				articleId: "",
				commentTotal: 0,
			}
		},
		onLoad(e) {
			this.articleId = e.id
			this.getDetail(e.id)
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onReachBottom() {
			uni.$emit('onReachBottom')
		},
		methods: {
			getDetail(id) {
				this.loading = true
				getArticle(id).then(res => {
					console.log(res);
					this.detail = res
					this.detail.content = md.render(this.detail.content)
					this.loading = false
					uni.setNavigationBarTitle({
						title: this.detail.title
					})
				}).catch(() => {
					this.loading = false
				})

			}
		}

	}
</script>

<style lang="scss" scoped>
	.container {
		background-color: #FFF;

		.title {
			font-size: 52rpx;
			font-weight: bolder;
			padding: 30rpx 30rpx 20rpx;
		}

		.row {
			padding: 0 30rpx;
		}

		.content {
			user-select: text;
			-webkit-user-select: text;
			padding: 30rpx;
			font-size: 28rpx;
			line-height: 1.4;
		}

		.footer {
			padding: 0 30rpx;
			margin-top: -20rpx;
			display: flex;
			justify-content: space-between;

			text {
				color: #777;
				font-size: 18rpx;
			}
		}

		.bottom-nav {
			position: fixed;
			bottom: 0;
		}
	}
</style>